from sentinelsat import SentinelAPI, read_geojson, geojson_to_wkt
from datetime import date


def sentinel2Download():
    username = "liangjiahao"
    password = "liangjiahao"
    apiurl = "https://scihub.copernicus.eu/apihub/"
    pageurl = "https://scihub.copernicus.eu/dhus"
    api = SentinelAPI(username, password, pageurl, show_progressbars=True, timeout=None)
    footprint = geojson_to_wkt(read_geojson("E:\download\map (1).geojson"))
    products = api.query(footprint, date=("20190710", date(2019, 9, 30)), platformname="Sentinel-2", producttype='S2MSI2A', cloudcoverpercentage=(0, 30))
    for product in products:
        product_info = api.get_product_odata(product)
        print(product_info['title'])
        api.download(product)
    return


if __name__ == "__main__":
    sentinel2Download()


